package com.hmis.hmis.UserInterface.managementUI;

import com.hmis.dao.*;
import com.hmis.domain.*;
import com.hmis.domain.entityProperty.PatientProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;

//管理模块
public class Management {

    private static Management Management;
    private BedDAO bedDAO = BedDAO.bedDAO;
    private PrescriptionDAO prescriptionDAO = PrescriptionDAO.prescriptionDAO;
    private PresciptionMedicineDAO presciptionMedicineDAO = PresciptionMedicineDAO.presciptionMedicineDAO;
    private WardDAO wardDAO = WardDAO.wardDAO;
    private PatientDAO patientDAO = PatientDAO.patientDAO;
    private DepartmentDAO departmentDAO = DepartmentDAO.departmentDAO;
    private DoctorDAO doctorDAO = DoctorDAO.doctorDAO;
    private StackPane stackPane = new StackPane();
    private VBox main = new VBox(20);
    private StackPane top = new StackPane();
    private StackPane center = new StackPane();
    private HBox hbcenter = new HBox(50);
    private TextArea illness = new TextArea("");
    private TextArea diagnose = new TextArea("");
    private TextArea presciption = new TextArea("");
    private StackPane bottom = new StackPane();
    private TableView table = new TableView();
    private PatientProperty chooseRow = null;
    private Stage popwindows = new Stage();

    public static List<Doctor> doctorList_sk = new ArrayList<>();
    public static List<Department> departmentList_sk = new ArrayList<>();
    private Management() {
        initTop();
        initCenter();
        initButtom();
        main.setAlignment(Pos.CENTER);
        main.getChildren().addAll(top, center, bottom);
        main.prefWidthProperty().bind(stackPane.maxWidthProperty().multiply(1));
        main.prefHeightProperty().bind(stackPane.maxHeightProperty().multiply(1));

        stackPane.getChildren().addAll(main);
        stackPane.setAlignment(Pos.CENTER);
        stackPane.setPrefWidth(1075);
        stackPane.setPrefHeight(700);


    }

    public static Management getManagement() {
        if (Management == null) {
            Management = new Management();
        }
        return Management;
    }

    public void refreshUI() {
        illness.setText("");
        diagnose.setText("");
        presciption.setText("");
    }

    private void initTop() {
        VBox vb1 = new VBox(20);
        Label lb1 = new Label("");
        lb1.setPrefHeight(20);
        vb1.getChildren().addAll(lb1);
        top.getChildren().add(vb1);
        top.setAlignment(Pos.CENTER);
    }

    private void initCenter() {
        table.setEditable(true);
        ObservableList<PatientProperty> data = FXCollections.observableArrayList();

        List<Patient> patients = patientDAO.list();
        for (Patient patient : patients) {
            if (patient.getStatus() == 0) {
                Doctor doctor = doctorDAO.findByName(patient.getDoctorName());
                data.add(new PatientProperty(patient.getPatientId(), patient.getPatientName(), patient.getSex(),
                        patient.getWardNo(), patient.getTheBedNo(), doctor.getDeptName(),
                        doctor.getDoctorName(), patient.getDiagnose(), patient.getCreateTime()
                ));
            }
        }
        TableColumn<PatientProperty, Long> patientIdCol = new TableColumn("病历号");
        patientIdCol.prefWidthProperty().bind(table.widthProperty().multiply(0.09));
        patientIdCol.setStyle("-fx-alignment: CENTER;");
        patientIdCol.setCellValueFactory(
                new PropertyValueFactory<>("patientId"));


        TableColumn<PatientProperty, String> patientNameCol = new TableColumn("病人姓名");
        patientNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.13));
        patientNameCol.setStyle("-fx-alignment: CENTER;");
        patientNameCol.setCellValueFactory(
                new PropertyValueFactory<>("patientName"));

        TableColumn<PatientProperty, String> sexCol = new TableColumn("性别");
        sexCol.prefWidthProperty().bind(table.widthProperty().multiply(0.12));
        sexCol.setStyle("-fx-alignment: CENTER;");
        sexCol.setCellValueFactory(
                new PropertyValueFactory<>("sex"));

        TableColumn<PatientProperty, Long> wardNoCol = new TableColumn("病房号");
        wardNoCol.prefWidthProperty().bind(table.widthProperty().multiply(0.09));
        wardNoCol.setStyle("-fx-alignment: CENTER;");
        wardNoCol.setCellValueFactory(
                new PropertyValueFactory<>("wardNo"));

        TableColumn<PatientProperty, Long> theBedNoCol = new TableColumn("床位号");
        theBedNoCol.prefWidthProperty().bind(table.widthProperty().multiply(0.09));
        theBedNoCol.setStyle("-fx-alignment: CENTER;");
        theBedNoCol.setCellValueFactory(
                new PropertyValueFactory<>("theBedNo"));

        TableColumn<PatientProperty, String> deptNameCol = new TableColumn("挂诊科室");
        deptNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.13));
        deptNameCol.setStyle("-fx-alignment: CENTER;");
        deptNameCol.setCellValueFactory(
                new PropertyValueFactory<>("deptName"));

        TableColumn<PatientProperty, String> doctorNameCol = new TableColumn("主治医师");
        doctorNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.13));
        doctorNameCol.setStyle("-fx-alignment: CENTER;");
        doctorNameCol.setCellValueFactory(
                new PropertyValueFactory<>("doctorName"));

        TableColumn<PatientProperty, String> createTimeCol = new TableColumn("入院日期");
        createTimeCol.prefWidthProperty().bind(table.widthProperty().multiply(0.22));
        createTimeCol.setStyle("-fx-alignment: CENTER;");
        createTimeCol.setCellValueFactory(
                new PropertyValueFactory<>("createTime"));

        table.getColumns().addAll(patientIdCol, patientNameCol, sexCol, wardNoCol, theBedNoCol, deptNameCol,
                doctorNameCol, createTimeCol);

        table.setPrefHeight(700);
        table.setPrefWidth(1100);
        table.setItems(data);

        VBox vb = new VBox(5);
        Label lb1 = new Label("");
        lb1.setPrefHeight(50);
        Label lb2 = new Label("");
        lb2.setPrefHeight(20);
        Label lb3 = new Label("");
        lb3.setPrefHeight(10);
        HBox hb = new HBox(100);
        hb.setAlignment(Pos.CENTER);
        Button refresh = new Button("刷新");
        refresh.setPrefSize(80, 25);
        Button modify = new Button("修改");
        modify.setPrefSize(80,25);
        Button discharge = new Button("出院");
        discharge.setPrefSize(80, 25);
        hb.getChildren().addAll(refresh, modify, discharge);
        vb.getChildren().addAll(lb1, table, lb2, hb, lb3);

        final String[] patientName = new String[1];
        final Long[] wardNo = new Long[1];
        final Long[] theBedNo = new Long[1];

        table.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<PatientProperty>() {
            @Override
            public void changed(ObservableValue<? extends PatientProperty> observable, PatientProperty oldValue, PatientProperty newValue) {
                if(newValue==null) {
                    chooseRow = null;
                    return;
                }
                chooseRow = newValue;
                patientName[0] = chooseRow.getPatientName();
                wardNo[0] = chooseRow.getWardNo();
                theBedNo[0] = chooseRow.getTheBedNo();

                illness.setText("\t" + patientDAO.findByName(patientName[0]).getIllness());
                diagnose.setText("\t" + patientDAO.findByName(patientName[0]).getDiagnose());
                presciption.setText("");
                String text = "";
                Prescription byPatientId = prescriptionDAO.getByPatientId(patientDAO.findByName(patientName[0]).getPatientId());
                int i = 1;
                if (byPatientId != null) {
                    text += "处方:" + "：\n";
                    for (PrescriptionMedicine pm : presciptionMedicineDAO.listByPrescriptionId(byPatientId.getPrescriptionId())) {
                        text += i + "、";
                        i++;
                        text += pm.getMedicine()+"\n";
                    }
                }

//
//                for (Prescription p : prescriptionDAO.listByPatientName(patientName[0])) {
//                    text += "处方" + i + "：";
//                    for (PrescriptionMedicine pm : presciptionMedicineDAO.listByPrescriptionId(p.getPrescriptionId())) {
//                        text += pm.getMedicine();
//                        text += "、";
//                    }
//                    text = text.substring(0, text.length() - 1);
//                    text += "\n\n";
//                    i++;
//                }
                presciption.setText(text);
            }
        });


        refresh.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                update();
                refreshUI();
            }
        });

        modify.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(chooseRow==null) {
                    return;
                }
                Patient patient = patientDAO.findByName(patientName[0]);

                if(popwindows.isShowing()) {
                    popwindows.close();
                }
                StackPane ms = new StackPane();
                VBox vb = new VBox(15);
                vb.setPrefWidth(350);
                vb.setAlignment(Pos.CENTER);

                Label op1 = new Label("");
                op1.setPrefHeight(10);

                Label titie1 = new Label("选择修改的字段");
                ComboBox<String> columns = new ComboBox<>();
//                columns.getItems().addAll("病人姓名", "性别", "病房号", "床位号", "挂诊科室", "主治医师");
                columns.getItems().addAll("病人姓名", "性别", "挂诊科室", "主治医师");
                columns.prefWidth(200);

                Label op2 = new Label("");
                op2.setPrefHeight(20);

                HBox hb = new HBox(30);
                hb.setAlignment(Pos.CENTER);
                Label hop1 = new Label("");
                hop1.setPrefWidth(10);
                Button pu = new Button("提交");
                pu.setPrefSize(50,20);

                Button re = new Button("重置");
                re.setPrefSize(50,20);

                Button ex = new Button("退出");
                ex.setPrefSize(50,20);
                Label hop2 = new Label("");
                hop2.setPrefWidth(10);
                hb.getChildren().addAll(hop1, re, ex, hop2);

                Label op3 = new Label("");
                op3.setPrefWidth(10);


                vb.getChildren().addAll(op1, titie1, columns, op2, hb, op3);
                ms.getChildren().addAll(vb);
                Scene scene = new Scene(ms,350,450);
                popwindows.setScene(scene);
                popwindows.show();

                re.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        columns.getSelectionModel().clearSelection();
                        vb.getChildren().clear();
                        ms.getChildren().clear();
                        vb.getChildren().addAll(op1, titie1, columns, op2, hb, op3);
                        ms.getChildren().addAll(vb);
                    }
                });

                ex.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        popwindows.close();
                    }
                });

                //更改一次选择即更新一次页面
                columns.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
                    @Override
                    public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                        if(newValue==null) {
                            return;
                        }
                        vb.getChildren().clear();
                        hb.getChildren().clear();
                        hb.getChildren().addAll(hop1,pu,re,ex,hop2);
                        TextField field = new TextField("");
                        Label tip = new Label("");
                        tip.setStyle("-fx-font: 18 arial;-fx-text-fill: red");

                        ComboBox<Long> wardno = new ComboBox<>();
                        wardno.setPromptText("病房号");
                        wardno.setPrefWidth(100);
                        ComboBox<Long> bedno = new ComboBox<>();
                        bedno.setPromptText("病床号");
                        bedno.setPrefWidth(100);
                        ComboBox<String> dept = new ComboBox<>();
                        dept.setPromptText("挂诊科室");
                        dept.setPrefWidth(100);
                        ComboBox<String> doctname = new ComboBox<>();
                        doctname.setPromptText("主治医师");
                        doctname.setPrefWidth(100);

                        switch(newValue) {
                            case "病人姓名" :
                                vb.getChildren().addAll(op1, titie1, columns, tip, field, op2, hb, op3);
                                ms.getChildren().clear();
                                ms.getChildren().addAll(vb);

                                pu.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {
                                        if(field.getText()=="") {
                                            tip.setText("输入不能为空");
                                            return;
                                        }
                                        patient.setPatientName(field.getText());
                                        patientDAO.updatePatientName(patient);
                                        tip.setText("提交成功");
                                        update();
                                        refreshUI();
                                    }
                                });
                                break;
                            case "性别" :
                                vb.getChildren().addAll(op1, titie1, columns, tip, field, op2, hb, op3);
                                ms.getChildren().clear();
                                ms.getChildren().addAll(vb);

                                pu.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {
                                        if(field.getText()=="") {
                                            tip.setText("输入不能为空");
                                            return;
                                        }
                                        patient.setSex(field.getText());
                                        patientDAO.updatePatient(patient);
                                        tip.setText("提交成功");
                                        update();
                                        refreshUI();
                                    }
                                });
                                break;

                            case "床位号" :
                                bedno.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                    @Override
                                    public void handle(MouseEvent event) {
                                        bedno.getItems().clear();
                                        List<Bed> bedList = bedDAO.listBedsWithWardNo(patient.getWardNo());
                                        for(Bed bed : bedList) {
                                            if(patient.getTheBedNo()!=bed.getTheBedNo()) {
                                                bedno.getItems().add(bed.getTheBedNo());
                                            }
                                        }
                                    }
                                });
                                vb.getChildren().addAll(op1, titie1, columns, tip, bedno, op2, hb, op3);
                                ms.getChildren().clear();
                                ms.getChildren().addAll(vb);

                                pu.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {
                                        if(bedno.getSelectionModel().getSelectedItem()==null) {
                                            tip.setText("请完成选择再提交");
                                            return;
                                        }
                                        Bed bed = bedDAO.findByWardNoAndTheBedNo(patient.getWardNo(),patient.getTheBedNo());
                                        bed.setStatus(0);
                                        bedDAO.updateByEntity(bed);
                                        //patient.setWardNo(bed.getWardNo());
                                        patient.setTheBedNo(bedno.getSelectionModel().getSelectedItem());
                                        patientDAO.updatePatient(patient);

                                        bed = bedDAO.findByWardNoAndTheBedNo(patient.getWardNo(),patient.getTheBedNo());
                                        bed.setStatus(1);
                                        bedDAO.updateByEntity(bed);
                                        tip.setText("提交成功");
                                        update();
                                        refreshUI();
                                    }
                                });
                                break;
                            case "主治医师" :
                                doctname.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                    @Override
                                    public void handle(MouseEvent event) {
                                        doctname.getItems().clear();
                                        List<Doctor> doctorList = doctorDAO.listByDeptment(patient.getDeptName());
                                        doctorList_sk = doctorList;
                                        for(Doctor doctor : doctorList) {
                                            doctname.getItems().add(doctor.getDoctorName());
                                        }
                                    }
                                });
                                vb.getChildren().addAll(op1, titie1, columns, tip, doctname, op2, hb, op3);
                                ms.getChildren().clear();
                                ms.getChildren().addAll(vb);

                                pu.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {
                                        if(doctname.getSelectionModel().getSelectedItem()==null) {
                                            tip.setText("请完成选择再提交");
                                            return;
                                        }
                                        Doctor doctor = doctorList_sk.get(doctname.getSelectionModel().getSelectedIndex());
                                        patient.setDoctorId(doctor.getDoctorId());
                                        patient.setDoctorName(doctname.getSelectionModel().getSelectedItem());
                                        patientDAO.updatePatient(patient);
                                        tip.setText("提交成功");
                                        update();
                                        refreshUI();
                                    }
                                });
                                break;
                            case "病房号" :
                                vb.getChildren().addAll(op1, titie1, columns, tip, wardno, bedno, op2, hb, op3);
                                ms.getChildren().clear();
                                ms.getChildren().addAll(vb);
                                wardno.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                    @Override
                                    public void handle(MouseEvent event) {
                                        wardno.getItems().clear();
                                        List<Ward> wardList = wardDAO.listWards();
                                        for(Ward ward : wardList) {
                                            if(patient.getWardNo()!=ward.getWardNo()) {
                                                wardno.getItems().add(ward.getWardNo());
                                            }
                                        }
                                    }
                                });

                                wardno.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Long>() {
                                    @Override
                                    public void changed(ObservableValue<? extends Long> observable, Long oldValue, Long newValue) {
                                        bedno.getItems().clear();
                                    }
                                });

                                bedno.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                    @Override
                                    public void handle(MouseEvent event) {
                                        if(wardno.getSelectionModel().getSelectedItem()==null) {
                                            tip.setText("请先选择病房号");
                                            return;
                                        }
                                        bedno.getItems().clear();
                                        List<Bed> bedList = bedDAO.listBedsWithWardNo(wardno.getSelectionModel().getSelectedItem());
                                        for(Bed bed : bedList) {
                                            if(bed.getStatus()==0) {
                                                bedno.getItems().add(bed.getTheBedNo());
                                            }
                                        }
                                    }
                                });

                                pu.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {
                                        if(wardno.getSelectionModel().getSelectedItem()==null||bedno.getSelectionModel().getSelectedItem()==null) {
                                            tip.setText("请完成选择再提交");
                                            return;
                                        }
                                        Bed bed = bedDAO.findByWardNoAndTheBedNo(patient.getWardNo(), patient.getTheBedNo());
                                        bed.setStatus(0);
                                        bedDAO.updateByEntity(bed);

                                        patient.setWardNo(wardno.getSelectionModel().getSelectedItem());
                                        patient.setTheBedNo(bedno.getSelectionModel().getSelectedItem());

                                        bed = bedDAO.findByWardNoAndTheBedNo(wardno.getSelectionModel().getSelectedItem(), bedno.getSelectionModel().getSelectedItem());
                                        bed.setStatus(1);
                                        bedDAO.updateByEntity(bed);

                                        patient.setBedNo(bed.getBedNo());
                                        patientDAO.updatePatient(patient);
                                        tip.setText("提交成功");
                                        update();
                                        refreshUI();

                                    }
                                });

                                break;

                            case "挂诊科室" :
                                vb.getChildren().addAll(op1, titie1, columns, tip, dept, doctname, op2, hb, op3);
                                ms.getChildren().clear();
                                ms.getChildren().addAll(vb);

                                dept.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                    @Override
                                    public void handle(MouseEvent event) {
                                        dept.getItems().clear();
                                        List<Department> departmentList = departmentDAO.list();
                                        departmentList_sk = departmentList;
                                        for(Department department : departmentList) {
                                            dept.getItems().add(department.getDeptName());
                                        }
                                    }
                                });
                                dept.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
                                    @Override
                                    public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                                        doctname.getItems().clear();
                                    }
                                });
                                doctname.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                    @Override
                                    public void handle(MouseEvent event) {
                                        if(dept.getSelectionModel().getSelectedItem()==null) {
                                            tip.setText("请先选择部门");
                                            return;
                                        }
                                        doctname.getItems().clear();
                                        List<Doctor> doctors = doctorDAO.listByDeptment(dept.getSelectionModel().getSelectedItem());
                                        doctorList_sk  = doctors;
                                        for(Doctor doctor : doctors) {
                                            doctname.getItems().add(doctor.getDoctorName());
                                        }

                                    }
                                });
                                pu.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {
                                        if(dept.getSelectionModel().getSelectedItem()==null||doctname.getSelectionModel().getSelectedItem()==null) {
                                            tip.setText("请完成选择再提交");
                                            return;
                                        }
                                        patient.setDeptId(departmentList_sk.get(dept.getSelectionModel().getSelectedIndex()).getDeptId());
                                        patient.setDeptName(dept.getSelectionModel().getSelectedItem());
                                        patient.setDoctorId(doctorList_sk.get(doctname.getSelectionModel().getSelectedIndex()).getDoctorId());
                                        patient.setDoctorName(doctname.getSelectionModel().getSelectedItem());
                                        patientDAO.updatePatient(patient);
                                        tip.setText("提交成功");
                                        update();
                                        refreshUI();
                                    }
                                });
                                break;

                            default: break;
                        }

                    }
                });
            }
        });

        discharge.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(chooseRow==null) {
                    return;
                }
                StackPane stackPane = new StackPane();
                VBox vBox = new VBox(25);
                vBox.setAlignment(Pos.CENTER);
                Label op1 = new Label("");
                op1.setPrefHeight(30);
                Label label = new Label("是否确认病人已经出院");
                label.setStyle("-fx-font: 18 arial");
                label.setPrefHeight(50);
                label.setAlignment(Pos.CENTER);
                HBox hBox = new HBox(50);
                hBox.setAlignment(Pos.CENTER);
                Button yes = new Button("是");
                Button no = new Button("否");
                yes.setPrefSize(60, 20);
                no.setPrefSize(60, 20);
                hBox.getChildren().addAll(yes, no);
                Label op2 = new Label("");
                op2.setPrefHeight(5);
                vBox.getChildren().addAll(op1, label, hBox, op2);
                stackPane.getChildren().addAll(vBox);

                Scene choose = new Scene(stackPane, 250, 200);
                Stage ch = new Stage();
                ch.setScene(choose);
                ch.show();

                yes.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        patientDAO.deletePatient(patientName[0], wardNo[0], theBedNo[0]);
                        bedDAO.refreshBed(wardNo[0], theBedNo[0]);
                        table.getSelectionModel().clearSelection();
                        ch.close();
                        update();
                        refreshUI();
                    }
                });

                no.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        ch.close();
                    }
                });

            }
        });


        VBox vBox = new VBox(10);
        vBox.setAlignment(Pos.CENTER);
        Label op1 = new Label("");
        op1.setPrefHeight(10);
        VBox v1 = new VBox(5);
        Label lbill = new Label("病情");
        lbill.setStyle("-fx-font: 18 arial");
        lbill.setAlignment(Pos.CENTER);

        v1.getChildren().addAll(lbill, illness);

        Label op2 = new Label("");
        op2.setPrefHeight(30);

        VBox v2 = new VBox(5);
        Label lbdiag = new Label("诊断");
        lbdiag.setStyle("-fx-font: 18 arial");
        lbdiag.setAlignment(Pos.CENTER);
        v2.getChildren().addAll(lbdiag, diagnose);

        Label op3 = new Label("");
        op3.setPrefHeight(30);

        VBox v3 = new VBox(5);
        Label lbpre = new Label("处方");
        lbpre.setStyle("-fx-font: 18 arial");
        lbpre.setAlignment(Pos.CENTER);
        v3.getChildren().addAll(lbpre, presciption);

        Label op4 = new Label("");
        vBox.getChildren().addAll(op1, v1, op2, v2, op3, v3, op4);

        illness.setPrefHeight(200);
        diagnose.setPrefHeight(200);
        presciption.setPrefHeight(200);

        illness.setWrapText(true);
        diagnose.setWrapText(true);
        presciption.setWrapText(true);

        illness.setEditable(false);
        diagnose.setEditable(false);
        presciption.setEditable(false);

        hbcenter.getChildren().addAll(vb, vBox);
        center.getChildren().addAll(hbcenter);


    }

    private void initButtom() {
        Label lb = new Label("");
        lb.setPrefHeight(10);
        bottom.getChildren().add(lb);

    }

    private void update() {
        ObservableList<PatientProperty> data = FXCollections.observableArrayList();

        table.getItems().clear();

        List<Patient> patients = patientDAO.list();
        for (Patient patient : patients) {
            if (patient.getStatus() == 0) {
                Doctor doctor = doctorDAO.findByName(patient.getDoctorName());
                data.add(new PatientProperty(patient.getPatientId(), patient.getPatientName(), patient.getSex(),
                        patient.getWardNo(), patient.getTheBedNo(), doctor.getDeptName(),
                        doctor.getDoctorName(), patient.getDiagnose(), patient.getCreateTime()
                ));
            }
        }

        table.setItems(data);
    }

    public StackPane getStackPane() {
        update();
        return stackPane;
    }

}
